<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:awc="clr-namespace:Assergs.Windows.Controls"
    xmlns:aw="clr-namespace:Assergs.Windows"
	>

    <SolidColorBrush x:Key="ForegroundBrush" Color="{x:Static aw:ExpanderPallet.Foreground}"/>
    <SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:ExpanderPallet.NormalBorder}"/>
    <SolidColorBrush x:Key="BodyBackgroundBrush" Color="{x:Static aw:ExpanderPallet.BodyBackground}" />
    <SolidColorBrush x:Key="GlyphBrush" Color="{x:Static aw:ExpanderPallet.Glyph}" />
    <SolidColorBrush x:Key="ButtonExternalBorderBrush" Color="{x:Static aw:ExpanderPallet.ButtonExternalBorder}"/>
    <SolidColorBrush x:Key="ButtonInternalBorderBrush" Color="{x:Static aw:ExpanderPallet.ButtonInternalBorder}"/>

    <LinearGradientBrush x:Key="HeaderBorderBrush" StartPoint="0,0.5" EndPoint="1,0.5">
        <GradientStop Color="{x:Static aw:ExpanderPallet.HeaderBackground1}" Offset="0"/>
        <GradientStop Color="{x:Static aw:ExpanderPallet.HeaderBackground2}" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="HeaderBackgroundBrush" StartPoint="0,0.5" EndPoint="1,0.5">
        <GradientStop Color="{x:Static aw:ExpanderPallet.HeaderBackground2}" Offset="0"/>
        <GradientStop Color="{x:Static aw:ExpanderPallet.HeaderBackground1}" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ButtonBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonBackground2}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ButtonLightBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonLightBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonLightBackground2}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ButtonPlusLightBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonPlusLightBackground1}" Offset="0"></GradientStop>
        <GradientStop Color="{x:Static aw:ExpanderPallet.ButtonPlusLightBackground2}" Offset="1"></GradientStop>
    </LinearGradientBrush>

    <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="20"/>
            </Grid.ColumnDefinitions>
            
            <Border
                Grid.Column="0"
                Background="Transparent"/>

            <Grid Grid.Column="1" Width="18" Height="18" VerticalAlignment="Center" HorizontalAlignment="Center">
                <Ellipse
                    Name="external"
                    Stroke="{StaticResource ButtonExternalBorderBrush}"
                    StrokeThickness="1"/>
                <Ellipse
                    Name="internal"
                    Margin="1"
                    Fill="White"
                    Stroke="{StaticResource ButtonInternalBorderBrush}"
                    StrokeThickness="1"/>
                <Path
                    Name="Arrow"
                    Stroke="{StaticResource GlyphBrush}"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Data="M 0 0 L 3 3 L 6 0 M 0 3 L 3 6 L 6 3"/>
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter TargetName="internal" Property="Fill" Value="{StaticResource ButtonLightBackgroundBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="internal" Property="Fill" Value="{StaticResource ButtonPlusLightBackgroundBrush}" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="Arrow" Property="Data" Value="M 0 3 L 3 0 L 6 3 M 0 6 L 3 3 L 6 6" />
            </Trigger>
            <!--<Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>-->
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <Style TargetType="Expander">
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Self}, Path=ExpandDirection}" Value="Down">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Expander">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Name="ContentRow" Height="0"/>
                                </Grid.RowDefinitions>
                                <Border
                            Name="Border"
                            Grid.Row="0"
                            Background="{StaticResource HeaderBackgroundBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}"
                            BorderThickness="1"
                            CornerRadius="2,2,0,0" >
                                    <Grid>
                                        <ContentPresenter
                                    Margin="4"
                                    ContentSource="Header"
                                    RecognizesAccessKey="True" />
                                        <ToggleButton Background="Yellow"
                                    IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                    OverridesDefaultStyle="True"
                                    Template="{StaticResource ExpanderToggleButton}"/>
                                    </Grid>
                                </Border>
                                <Border
                          Name="Content"
                          Grid.Row="1"
                          Background="{StaticResource BodyBackgroundBrush}"
                          BorderBrush="{StaticResource NormalBorderBrush}"
                          BorderThickness="1,0,1,1"
                          CornerRadius="0,0,2,2" >
                                    <ContentPresenter Margin="4" />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}" />
                                </Trigger>
                                <!--<Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>-->
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Self}, Path=ExpandDirection}" Value="Right">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Expander">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Name="ContentColumn" Width="0"/>
                                </Grid.ColumnDefinitions>
                                <Border
                            Name="Border"
                            Grid.Column="0"
                            Background="{StaticResource HeaderBackgroundBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}"
                            BorderThickness="1"
                            CornerRadius="2,0,0,2" >
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Grid  Grid.Row="1">
                                            <Grid.LayoutTransform>                                                
                                                    <TransformGroup>
                                                        <RotateTransform Angle="-90"/>
                                                    </TransformGroup>                                                
                                            </Grid.LayoutTransform>
                                            <ContentPresenter
                                    Margin="4" 
                                    ContentSource="Header"
                                    RecognizesAccessKey="True"  >                                                
                                            </ContentPresenter>
                                        </Grid>                                        
                                        <ToggleButton Background="Yellow" Grid.Row="0"
                                    IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                    OverridesDefaultStyle="True"
                                    Template="{StaticResource ExpanderToggleButton}">
                                            <ToggleButton.LayoutTransform>
                                                <TransformGroup>
                                                    <RotateTransform Angle="270"/>                                                    
                                                </TransformGroup>
                                            </ToggleButton.LayoutTransform>
                                        </ToggleButton>
                                    </Grid>
                                </Border>
                                <Border
                          Name="Content"
                          Grid.Column="1"
                          Background="{StaticResource BodyBackgroundBrush}"
                          BorderBrush="{StaticResource NormalBorderBrush}"
                          BorderThickness="0,1,1,1"
                          CornerRadius="0,2,2,0" >
                                    <ContentPresenter Margin="4" />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentColumn" Property="Width" Value="{Binding ElementName=Content,Path=DesiredWidth}" />
                                </Trigger>
                                <!--<Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>-->
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding  RelativeSource={RelativeSource Self}, Path=ExpandDirection}" Value="Left">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Expander">
                            <Grid>
                                <Grid.ColumnDefinitions>                                    
                                    <ColumnDefinition Name="ContentColumn" Width="0"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Border
                            Name="Border"
                            Grid.Column="1"
                            Background="{StaticResource HeaderBackgroundBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}"
                            BorderThickness="1"
                            CornerRadius="2,0,0,2" >
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Grid  Grid.Row="1">
                                            <Grid.LayoutTransform>
                                                <TransformGroup>
                                                    <RotateTransform Angle="90"/>
                                                </TransformGroup>
                                            </Grid.LayoutTransform>
                                            <ContentPresenter
                                    Margin="4" 
                                    ContentSource="Header"
                                    RecognizesAccessKey="True"  >
                                            </ContentPresenter>
                                        </Grid>
                                        <ToggleButton Background="Yellow" Grid.Row="0"
                                    IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                    OverridesDefaultStyle="True"
                                    Template="{StaticResource ExpanderToggleButton}">
                                            <ToggleButton.LayoutTransform>
                                                <TransformGroup>
                                                    <RotateTransform Angle="270"/>
                                                </TransformGroup>
                                            </ToggleButton.LayoutTransform>
                                        </ToggleButton>
                                    </Grid>
                                </Border>
                                <Border
                          Name="Content"
                          Grid.Column="0"
                          Background="{StaticResource BodyBackgroundBrush}"
                          BorderBrush="{StaticResource NormalBorderBrush}"
                          BorderThickness="0,1,1,1"
                          CornerRadius="0,2,2,0" >
                                    <ContentPresenter Margin="4" />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentColumn" Property="Width" Value="{Binding ElementName=Content,Path=DesiredWidth}" />
                                </Trigger>
                                <!--<Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>-->
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>        
    </Style>

</ResourceDictionary>